import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:nyh_motorcade_app/styles/colors.dart';

class LoadingDialog extends Dialog {
  final String? message;

  LoadingDialog({Key? key, this.message}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Material(
      type: MaterialType.transparency,
      child: Center(
        child: Container(
          width: 100.w,
          height: 100.w,
          decoration: BoxDecoration(
            color: Colours.color_translucent,
            borderRadius: BorderRadius.all(Radius.circular(5.w)),
            border: Border.all(color: Colours.color_translucent),
          ),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              CircularProgressIndicator(
                strokeWidth: 1,
              ),
              SizedBox(
                height: ScreenUtil().setWidth(10),
              ),
              Text(
                message ?? "",
                style: TextStyle(color: Colours.color_white, fontSize: 10.sp),
              )
            ],
          ),
        ),
      ),
    );
  }

  static void showCustomDialog(BuildContext? context, {String message = "加载中..."}) {
    if (context == null) {
      return;
    }
    showDialog(
        context: context,
        builder: (context) {
          return LoadingDialog(message: message);
        },
        barrierDismissible: false);
  }

  static void dismissDialog(BuildContext? context) {
    if (context == null) {
      return;
    }
    Navigator.pop(context);
  }
}
